#if DEBUG

using System;
using System.Xml.Linq;
using FluentlyXml.Core;
using FluentlyXml.Core.DSL;
using FluentlyXml.UnitTests.Core.TestObjects;
using NUnit.Framework;

namespace FluentlyXml.UnitTests.Core
{
	public class XidgetTests
	{
		[TestFixture]
		public class When_serializing_a_xidget
		{
			private XElement _xml;
			private Xidget _parent;
			private Xidget _child;

			[SetUp]
			public void When()
			{
				var factory = new FluentSerializerFactory(x =>
				                                          	{
				                                          		x.ApplyConfigFrom<XidgetSerializationSpec>();
				                                          	});

				var serializer = factory.CreateSerializer();

				_parent = new Xidget {XidgetID = Guid.NewGuid(), Dummy1 = "Blah"};
				_child = new Xidget {XidgetID = Guid.NewGuid(), Dummy1 = "Blah"};
				_child.Parent = _parent;
				_parent.Child = _child;

				_xml = serializer.Serialize(_parent);
			}

			[Test]
			public void Then_it_does_not_serialize_ignored_properties_from_the_base_type()
			{
				Assert.That(_xml.ToString(), Is.Not.StringContaining("Blah"));
			}

			[Test]
			public void Then_it_serializes_parent_using_its_id()
			{
				Assert.That(_xml.ToString(), Is.StringContaining("<Parent>" + _parent.XidgetID));
			}
		}
	}

	public class XidgetSerializationSpec : FluentSerializationSpec
	{
		public XidgetSerializationSpec()
		{
			WhenSerializing<Xidget>()
				//TODO: This is not ideal.  You really shouldn't have to check a property for null, the default
				//		should be to skip properties... there should be an easier way to handle this. :( 
				.Serialize(x => x.Parent).Using(x => x.Parent != null ? x.Parent.XidgetID.ToString() : "")
				.Ignore(x => x.Dummy1);
		}
	}
}

#endif